package entity

import (
	"github.com/lab-online/internal/shared/valueobject"
	"github.com/lab-online/pkg/util"
)

func (r *Report) ApplyContentPatch(content []byte) error {
	modify, err := util.ApplyJSONPatch([]byte(r.Content), content)
	if err == nil {
		r.Content = string(modify)
	}
	return err
}

func (r *Report) ApplyStatusPatch(statusPatch []valueobject.Patch[uint]) {
	for _, patch := range statusPatch {
		switch {
		case patch.IsAdd():
			r.Status = util.BitMaskSet(r.Status, patch.Value)
		case patch.IsRemove():
			r.Status = util.BitMaskUnset(r.Status, patch.Value)
		default:
			r.Status = patch.Value
		}
	}
}
